import {
  querySensLevel, //敏感等级信息分布
  querySensType, //敏感类型
  querySensWord, //敏感信息
} from '@/services/sensitiveData/moreStatistics';

export default {
  namespace: 'moreStatistics',
  state: {   
    querySensLevelData: [],//敏感等级信息分布
    querySensTypeData: [],//敏感类型
    querySensWordData: [],//敏感信息
  },
  effects: {
    // 敏感等级信息分布（饼图）
    *querySensLevel({ payload }, { call, put }) {
      const response = yield call(querySensLevel, payload);
      yield put({
        type: 'saveSensLevel',
        payload: response.data.dataList || [],
      });
    },

     // 敏感类型（饼图）
     *querySensType({ payload }, { call, put }) {
      const response = yield call(querySensType, payload);
      yield put({
        type: 'saveSensType',
        payload: response.data.dataList || [],
      });
    },

     // 敏感信息（柱状图）
     *querySensWord({ payload }, { call, put }) {
      const response = yield call(querySensWord, payload);
      yield put({
        type: 'saveSensWord',
        payload: response.data.dataList || [],
      });
    },

  },
  reducers: {
    // 敏感等级信息分布（饼图）
    saveSensLevel(state, { payload }) {
      payload.map(e => [(e.x = e.name), (e.y = Number(e.num))]);
      return {
        ...state,
        querySensLevelData: payload || [],
      };
    },  

     // 敏感类型（饼图）
     saveSensType(state, { payload }) {
      payload.map(e => [(e.x = e.name), (e.y = Number(e.num))]);
      return {
        ...state,
        querySensTypeData: payload || [],
      };
    },  

     // 敏感信息（柱状图）
     saveSensWord(state, { payload }) {
      payload.map(e => [(e.x = e.name), (e.y = Number(e.num))]);
      return {
        ...state,
        querySensWordData: payload || [],
      };
    },  

  },
};
